<?php

/**
* AdminShowRouteFormModule.class.php
*
* Concrete page module shows route overview
*
* @author     Blazej Zieba <b@zieba.info>
* @copyright  2007 konekto.com
* @version    CVS: $Id:$
*/

require_once("framework/PageModule.class.php");
require_once("HTML/QuickForm.php");
require_once("HTML/QuickForm/Renderer/Default.php");


// {{{ SlideShowListModule

class AdminShowRouteFormModule extends PageModule 
{
    // {{{ Class operations 

    // {{{ SlideShowListModule
    /**
    * C'tor
    */
    
    function AdminShowRouteFormModule()
    {
        trigger_error("ENTER AdminShowRouteFormModule::AdminShowRouteFormModule()", E_USER_NOTICE);
    }
    // }}}
    // {{{ getContent

    /**
    * Function returns page content
    *
    */

    function getContent()
    {

        trigger_error("ENTER AdminShowRouteFormModule::getContent()", E_USER_NOTICE);
        $form = new HTML_QuickForm("GuideListForm", 'post', 'index.php?cmd=AdminShowRoute');


        $options = &PEAR::getStaticProperty('CONFIG_INI','DSN');    
        $global = &PEAR::getStaticProperty('CONFIG_INI','GLOBAL');    

        $dbh = new PDO($options['dsn_string']);
        $dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );



        $sth = $dbh->prepare("SELECT rowid, name FROM guide WHERE rowid = :id AND owner = :owner");  
        $sth->bindParam(':id',$_GET['id'],PDO::PARAM_INT);
        $sth->bindParam(':owner',AuthSingleton::instance()->getUsername(),PDO::PARAM_STR);
        $sth->execute();
        $result = $sth->fetchAll(PDO::FETCH_ASSOC);
        $form->addElement('static',null,null,_('Trasa:'));
        
        $group = array();
        $group[] =&  HTML_QuickForm::createElement('link',null,null, $global['service_url'].'index.php?cmd=AdminAddGuide&id='.$result[0]['rowid'],$result[0]['name'] );
        $group[] =&  HTML_QuickForm::createElement('link',null,null, $global['service_url'].'index.php?cmd=AdminSendCode&id='.$result[0]['rowid'],_('[Wyślij kody]') );
        $form->addGroup($group, null, null, '&nbsp;');
        //$form->addElement('link',null,null, $global['service_url'].'index.php?cmd=AdminAddGuide&id='.$result[0]['rowid'],$result[0]['name'] );

        $form->addElement('link',null,_('Slajdy '), $global['service_url'].'index.php?cmd=AdminAddSlide&guide_id='.$result[0]['rowid'],_('[Dodaj slajd]'));

        $sth = $dbh->prepare("SELECT rowid, guide_id, name FROM slide WHERE guide_id = :id AND owner = :owner ORDER BY `order` ASC");  
        $sth->bindParam(':id',$_GET['id'],PDO::PARAM_INT);
        $sth->bindParam(':owner',AuthSingleton::instance()->getUsername(),PDO::PARAM_STR);
        $sth->execute();
        

        $result = $sth->fetchAll(PDO::FETCH_ASSOC);
        
        $rowNum = 0;
        foreach ( $result as $row  )
        {  
            $group = array();
            $group[] =& HTML_QuickForm::createElement('static',null,null, ++$rowNum); 
            $group[] =& HTML_QuickForm::createElement('link',null,null, $global['service_url'].'index.php?cmd=AdminAddSlide&id='.$row['rowid'].'&guide_id='.$row['guide_id'],$row['name'] );
            $group[] =& HTML_QuickForm::createElement('link',null,null, $global['service_url'].'index.php?cmd=AdminRemoveSlide&id='.$row['rowid'].'&guide_id='.$row['guide_id'],_('[Usuń]'),array("id" => "AdminRemoveSlide".$row['rowid'].$row['guide_id']));
            $form->addGroup($group, null, null, '&nbsp;');
        }
                 
        $options = &PEAR::getStaticProperty('CONFIG_INI','TEMPLATES');
        $renderer =& new HTML_QuickForm_Renderer_Default($options);
        $renderer -> setFormTemplate(file_get_contents($options["templates_dir"]."form.tpl.xhtml"));
        $renderer -> setElementTemplate(file_get_contents($options["templates_dir"]."formElementStatic.tpl.xhtml"));

        $form->accept($renderer);

        $statusTpl = new HTML_Template_IT($options["templates_dir"]);
        $statusTpl->loadTemplatefile("status.tpl.xhtml",FALSE,FALSE);
        $statusTpl->setVariable("STATUS",_("Edytuj trase lub dodaj/edytuj slajd."));        
    
	    return $statusTpl->get().$renderer->toHtml().$statusTpl->get();
    }
    
    // }}}

    // }}}
}

// }}} 

?>
